package mx.com.fractal.ristorante.rest;

import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import mx.com.fractal.ristorante.dto.RestauranteDTO;
import mx.com.fractal.ristorante.exception.JdbcException;
import mx.com.fractal.ristorante.service.RestauranteService;

import org.jboss.resteasy.annotations.providers.jaxb.json.BadgerFish;

@Path("restaurante")
@Singleton
public class RestauranteRest {
	
	@Resource
	private RestauranteService restauranteService;

	@PUT @Path("save") @BadgerFish
	@Produces(value={MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
	public Response save(@QueryParam("nombre") String nombre,
			@QueryParam("razonSocial") String razonSocial){
		
		RestauranteDTO restaurante = new RestauranteDTO();
		restaurante.setNombre(nombre);
		restaurante.setRazonSocial(razonSocial);
		try {
			restauranteService.save(restaurante);
			return Response.ok().entity(restaurante).build();
		} catch (JdbcException e) {
			return Response.serverError().build();
		}
	}
}
